//
//  UIKitExampleStackView.m
//  MasonryExample
//
//  Created by 山刘 on 2020/6/12.
//  Copyright © 2020 山刘. All rights reserved.
//

#import "UIKitExampleStackView.h"

@implementation UIKitExampleStackView
+(BOOL)requiresConstraintBasedLayout{
    return YES;
}
- (id)init {
    self = [super init];
    if (!self) return nil;
    
    UIStackView *sv = [[UIStackView alloc] initWithFrame:CGRectMake(10, 10, KScreenWidth-20, 200)];
     
    UIView *subView1 = [LayoutUtils createView];
    UIView *subView2 = [LayoutUtils createView];
    UIView *subView3 = [LayoutUtils createView];
    
    subView1.backgroundColor = UIColor.redColor;
    subView2.backgroundColor = UIColor.greenColor;
    subView3.backgroundColor = UIColor.blueColor;
    
    [sv addArrangedSubview:subView1];
    [sv addArrangedSubview:subView2];
    [sv addArrangedSubview:subView3];
    
    [self addSubview:sv];
    return self;
}

-(void)test_init_3{
    
    UILabel *subLabel1 = [LayoutUtils fixedLabelWithText:@"40x100"];
    UILabel *subLabel2 = [LayoutUtils fixedLabelWithText:@"80x80"];
    UILabel *subLabel3 = [LayoutUtils fixedLabelWithText:@"100x50"];
    
    [subLabel1 sizeToFit];
    [subLabel2 sizeToFit];
    
    UIStackView *sv = [[UIStackView alloc] initWithArrangedSubviews:@[subLabel1,subLabel2,subLabel3]];
    [self addSubview:sv];
    subLabel1.frame = CGRectMake(0, 0, 40, 100);
    subLabel2.frame = CGRectMake(0, 0, 80, 80);
    subLabel3.frame = CGRectMake(0, 0, 100, 50);
    sv.frame = CGRectMake(10, 10, CGRectGetWidth(self.frame) - 20, 300);
}

-(void)test_init_2 {
    UILabel *subLabel1 = [LayoutUtils fixedLabelWithText:@"Sub1"];
    UILabel *subLabel2 = [LayoutUtils fixedLabelWithText:@"Sub2"];
    
    [subLabel1 sizeToFit];
    [subLabel2 sizeToFit];
    
    UIStackView *sv = [[UIStackView alloc] initWithArrangedSubviews:@[subLabel1,subLabel2]];
    [self addSubview:sv];
    
    NSArray<UIView *> *arrangedSubviews = sv.arrangedSubviews;
    NSLog(@"%@",arrangedSubviews);
    /*
     2020-06-12 09:42:19.734773+0800 MasonryExample[66066:3204972] (
     "<UILabel: 0x7f909d73d010; frame = (0 0; 0 0); text = 'Sub1'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x600000803200>>",
     "<UILabel: 0x7f909d7430b0; frame = (0 0; 0 0); text = 'Sub2'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000008032f0>>"
     )
     */
}
-(void)test_init_1 {
    UIStackView *sv = [LayoutUtils creatStackView];
    [self addSubview:sv];
    
    UIView *subView1 = [LayoutUtils createView];
    UIView *subView2 = [LayoutUtils createView];
    
    // 子View 实例加到 UIStackView 里
    [sv addArrangedSubview:subView1];
    [sv addArrangedSubview:subView2];
    
    NSArray<UIView *> *arrangedSubviews = sv.arrangedSubviews;
    NSLog(@"%@",arrangedSubviews);
    /*
     2020-06-12 09:39:59.898694+0800 MasonryExample[65963:3203047] (
     "<UIView: 0x7fcb28c40940; frame = (0 0; 0 0); layer = <CALayer: 0x6000039cfd60>>",
     "<UIView: 0x7fcb28c40ab0; frame = (0 0; 0 0); layer = <CALayer: 0x6000039cfda0>>"
     )
     */
}


@end
